#include "PlayerInfo.h"
#include "../Data/GameData.h"
#include "../GameConfig.h"
#include "cocos2d.h"
#define kPlayerNewGame "player_newgame"

USING_NS_CC;

PlayerInfo* PlayerInfo::m_instance = nullptr;

PlayerInfo* PlayerInfo::getInstance()
{
	if (m_instance == nullptr)
		m_instance = new PlayerInfo();
	return m_instance;
}

PlayerInfo::PlayerInfo()
{
	level = new LevelInfo();

	if (!UserDefault::getInstance()->getBoolForKey(kPlayerNewGame))
	{
		reset();
	}
}

void PlayerInfo::reset()
{
	UserDefault::getInstance()->setBoolForKey(kPlayerNewGame, true);

	level->setLevelEnable(EGameMode::kMode_Easy, 1, true);
	level->setLevelEnable(EGameMode::kMode_Normal, 1, true);
	level->setLevelEnable(EGameMode::kMode_Hard, 1, true);

	for (int i = 2; i <= GameData::getInstance()->config.NumOfEasyLevel; i++)
	{
		level->setLevelEnable(EGameMode::kMode_Easy, i, false);
	}

	for (int i = 2; i <= GameData::getInstance()->config.NumOfNormalLevel; i++)
	{
		level->setLevelEnable(EGameMode::kMode_Normal, i, false);
	}

	for (int i = 2; i <= GameData::getInstance()->config.NumOfHardLevel; i++)
	{
		level->setLevelEnable(EGameMode::kMode_Hard, i, false);
	}
}